package com.winchain.chainbill.bill.biz.discount.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.service.CbDctService;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillDctSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbDct>> {
	@Autowired
	private CbDctService cbDctService;

	public void onApplicationEvent(BillEvent<CbDct> t) {
		CbRec record = t.getBill().getRec();
		CbDct cbDct = (CbDct) t.getBill().getSource();
		if ((cbDct != null) && (cbDct.getDctId() != null)) {
			cbDct.setOptSeq(record.getOptSeq());
			this.cbDctService.saveOrUpdate(cbDct);
		}
	}
}
